package com.android.presenter.info;

import com.android.model.net.HttpObserver;
import com.android.presenter.base.BasePresenter;
import com.android.presenter.iview.IOrderResultView;
import com.android.model.entity.res.OrderResult;
import com.android.model.info.UserModel;
import com.android.util.log.LogUtil;

import java.math.BigDecimal;

/**
 * author:  TenFace
 * date:    2017/9/27
 * description: 下单
 */

public class CreateNewOrderPresenter extends BasePresenter<IOrderResultView> {

    private static final String TAG = CreateNewOrderPresenter.class.getSimpleName();
    private UserModel mUserModel;

    public CreateNewOrderPresenter(IOrderResultView iOrderResultView) {
        super(iOrderResultView);
        mUserModel = UserModel.getInstance();
    }

    public void createNewOrder(String accountId,
                               String ticket,
                               String token,
                               String symbol,
                               String orderType,
                               String orderSide,
                               BigDecimal quantity,
                               BigDecimal limitPrice) {

        mUserModel.createNewOrder(accountId, ticket, token, symbol, orderType, orderSide, quantity, limitPrice, new HttpObserver<OrderResult>() {
            @Override
            public void onSuccess(OrderResult orderResult) {
                LogUtil.e(TAG, "成功！");
                if (mIView != null) {
                    mIView.orderSuccess(orderResult);
                }
            }

            @Override
            public void onError(int errType, String errMessage) {
                LogUtil.e(TAG, "失败码：" + errType + "》》信息：" + errMessage);
                if (mIView != null) {
                    mIView.orderFail(errType, errMessage);
                }
            }
        }, mIView.getLifeSubject());
    }

}
